//运行统计	
$(function () {

	$.ajax({
		async: false,
		type : "post",
		url: "../vehicle/selectVehicleStatusByUser.do",
		datatype: "json",
		success : function(data){
			list = eval("("+data+")");
			list=list[0];
			$("#vehicle_number").html(list.count_vehicle);
			$("#online_number").html(list.count_online);
			$("#charging_number").html(list.count_charging);
			$("#warning_number").html(list.count_err);
			//构筑图表
	        Highcharts.chart('canvasDiv1', {
	            chart: {
	                plotBackgroundColor: null,
	                plotBorderWidth: null,
	                plotShadow: false,
	                type: 'pie'
	            },
	            title: {
	               // text: 'Browser market shares January, 2015 to May, 2015'
	            },
	            tooltip: {
	                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	            },
	            plotOptions: {
	                pie: {
	                    allowPointSelect: true,
	                    cursor: 'pointer',
	                    dataLabels: {
	                        enabled: false
	                    },
	                    showInLegend: true
	                }
	            },
	            series: [{
	                name: 'Brands',
	                colorByPoint: true,
	                data: [{
	                    name: '离线:'+list.count_offline+'('+(list.count_offline/list.count_vehicle*100).toFixed(1)+'%)',
	                    y: list.count_offline/list.count_vehicle
	                }, {
	                    name: '行驶:'+list.count_travel+'('+(list.count_travel/list.count_vehicle*100).toFixed(1)+'%)',
	                    y: list.count_travel/list.count_vehicle,
	                    sliced: true,
	                    selected: true
	                }, {
	                    name: '静止:'+list.count_stop+'('+(list.count_stop/list.count_vehicle*100).toFixed(1)+'%)',
	                    y: list.count_stop/list.count_vehicle
	                }, {
	                    name: '故障:'+list.count_err+'('+(list.count_err/list.count_vehicle*100).toFixed(1)+'%)',
	                    y: list.count_err/list.count_vehicle
	                }, {
	                    name: '充电:'+list.count_charging+'('+(list.count_charging/list.count_vehicle*100).toFixed(1)+'%)',
	                    y: list.count_charging/list.count_vehicle
	                }]
	            }]
	        });
         },
         error: function (XMLHttpRequest, textStatus, errorThrown) {
			
         }
     });
});



	
//节能减排图表		
$(function () {
    $('#chart2').highcharts({
        chart: {
            type: 'bar',
			backgroundColor:false
        },
        title: {
            text: '节能减排',
			color:'#fff',
			
        },
        xAxis: {
            categories: ['车型1', '车型2', '车型3', '车型4', '车型5'],
            title: {
                text: null
            },
			labels:{
				style:{
					fontSize:'14px',
					color:'#91bbc8',
					fontWeight:'bold'

				}	
			}
			
        },
        yAxis: {
            min: 0,
            title: {
                //text: 'Population (millions)',
                //align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            //valueSuffix: ' millions'
		
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true,
			
                }
				
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 100,
            floating: true,
           borderWidth: 1,
            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
            shadow: true
        },
        credits: {
            enabled: false,
			
        },
        series: [{
          name: '节能减排',
          data: [180, 50, 150, 200, 400],
		
			
        }]
    });
});
var list=[];
var hashList;
//地图图表
$(function () {
	//获取车辆省市信息
	$.ajax({
		async: false,
		type : "get",
		url: "../vehicle/selectLocationVehicleByUser.do",
		datatype: "json",
		success : function(data){
			list = eval("("+data+")");
			list=list[0];
         },
         error: function (XMLHttpRequest, textStatus, errorThrown) {

         }
     });
    Highcharts.setOptions({
        lang:{
            drillUpText:"返回 > {series.name}"
        }
    });
    var data =Highcharts.geojson(Highcharts.maps['countries/cn/custom/cn-all-china']),
    	small = $('#container').width() < 400;
    // 给城市设置随机数据
    $.each(data, function (i) {
        this.drilldown = this.properties['drill-key'];
       // this.value =eval(list+"."+(this.properties['cn-name']));
        this.value = list[this.properties['cn-name']];
        //alert(this.properties['cn-name']+"   "+hashList[this.properties['cn-name']]);
    });
    //初始化地图
    $('#container').highcharts('Map', {
        chart : {
            events: {
                drilldown: function (e) {
                    if (!e.seriesOptions) {
                        var chart = this;                             
                        var cname=e.point.properties["cn-name"];
                        chart.showLoading('<i class="icon-spinner icon-spin icon-3x"></i>');
                        // 加载城市数据
                        $.ajax({
                            type: "GET",
                            url: "http://data.hcharts.cn/jsonp.php?filename=GeoMap/json/"+ e.point.drilldown+".geo.json",
                            contentType: "application/json; charset=utf-8",
                            dataType:'jsonp',
                            crossDomain: true,
                            success: function(json) {
                                data = Highcharts.geojson(json);
                                $.each(data, function (i) {
                                	 this.value = list[this.properties['name']];
                                });
                                chart.hideLoading();

                                chart.addSeriesAsDrilldown(e.point, {
                                    name: e.point.properties["cn-name"],
                                    data: data,
                                    dataLabels: {
                                        enabled: true,
                                        format: '{point.name}'
                                    }
                                });
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {

                            }
                        });
                    }


                    this.setTitle(null, { text: cname });
                },
                drillup: function () {
                    this.setTitle(null, { text: '中国' });
                }
            }
        },
//        credits:{
//            href:"http://www.peng8.net/",
//            text:"www.peng8.net"
//        },
        title : {
            text : '车辆分布统计图'
        },
        subtitle: {
            text: '中国',
            floating: true,
            align: 'right',
            y: 50,
            style: {
                fontSize: '16px'
            }
        },
        legend: small ? {} : {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle'
        },
        //tooltip:{
        //pointFormat:"{point.properties.cn-name}:{point.value}"
        //},
        colorAxis: {
            min: 0,
            minColor: '#E6E7E8',
            maxColor: '#005645'
        },
        mapNavigation: {
            enabled: true,
            buttonOptions: {
                verticalAlign: 'bottom'
            }
        },
        plotOptions: {
            map: {
                states: {
                    hover: {
                        color: '#EEDD66'
                    }
                }
            }
        },
        series : [{
            data : data,
            name: '中国',
            dataLabels: {
                enabled: true,
                format: '{point.properties.cn-name}'
            }
        }],
        drilldown: {
            activeDataLabelStyle: {
                color: '#FFFFFF',               
                textDecoration: 'none',                
                textShadow: '0 0 3px #000000'            
                },            
       		drillUpButton: {                
        		relativeTo: 'spacingBox',                
        		position: {                    
        			x: 0,                    
        			y: 60                
        			}            
        		}        
        	}    
        });
 });
function quit(){
	if(confirm("是否确认退出系统?")){
			window.location="../login.jsp";
	   }
}
